package com.hucheng.seckill.entity;

import com.hucheng.common.utils.CommonUtils;
import com.hucheng.seckill.dto.OrderItemDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 持久层数据
 **/
@Data
public class OrderItemDO {
    private Integer itemId;
    private Integer orderId;
    private String orderItemNumber;
    private Integer status;
    private Integer formatId;
    private Integer userId;
    private String goodsName;
    private Integer goodsNumber;
    private BigDecimal goodsPrice;
    private BigDecimal goodsAmount;
    private Integer isDel;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;

    public static OrderItemDO buildOrderItemDO(final OrderItemDTO orderItemDTO) {
        if (orderItemDTO != null) {
            OrderItemDO orderDO = new OrderItemDO();

            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(orderItemDTO.getItemId()+"")) {
                orderDO.setItemId(orderItemDTO.getItemId());
                orderDO.setOrderItemNumber(CommonUtils.getOrderIdByTime());
                orderDO.setDateCreated(currentTime);
            }else{
                orderDO.setDateUpdated(currentTime);
            }
            orderDO.setOrderId(orderItemDTO.getOrderId());
            orderDO.setStatus(orderItemDTO.getStatus());
            orderDO.setFormatId(orderItemDTO.getFormatId());
            orderDO.setUserId(orderItemDTO.getUserId());
            orderDO.setGoodsName(orderItemDTO.getGoodsName());
            orderDO.setGoodsNumber(orderItemDTO.getGoodsNumber());
            orderDO.setGoodsPrice(orderItemDTO.getGoodsPrice());
            orderDO.setGoodsAmount(orderItemDTO.getGoodsAmount());
            orderDO.setIsDel(0);
            return orderDO;
        }
        return null;
    }
}
